// pages/peris/index.js

const customRequst = require('../../../common/customRequst.js');
const commomUser = require('../../../common/commonUser.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    periId: '',
    active: 0,
    periDetail: {},
    show: false,
    infoData: [{
        text: '主管单位',
        name: '',
      },
      {
        text: '主办单位',
        name: '',
      },
      {
        text: '国际刊号',
        name: '',
      },
      {
        text: '国内刊号',
        name: '',
      },
      {
        text: '投稿须知',
        name: '',
      },
      {
        text: '审核时长',
        name: '',
      },
      {
        text: '最新期次',
        name: '',
      },
      {
        text: '书刊媒介',
        name: '',
      },
      {
        text: '刊物页数',
        name: '',
      },
      {
        text: '摘要',
        name: '',
      },
      {
        text: '样刊说明',
        name: '',
      },
      {
        text: '查重说明',
        name: '',
      },
      {
        text: '邮寄说明',
        name: '',
      },
      {
        text: '参考文献',
        name: '',
      },
      {
        text: '刊物证书',
        name: '',
      },
      {
        text: '发票说明',
        name: '',
      },
      {
        text: '其他信息',
        name: '',
      }
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    that.data.periId = options.id;
    customRequst.postParamsRequest('api/peri/detail', {
      id: that.data.periId
    }).then(function (re) {
      if (re.code == 1) {
        that.setData({
          periDetail: re.data,
          'infoData[0].name': re.data.manager_info,
          'infoData[1].name': re.data.operator_info,
          'infoData[2].name': re.data.peri_issn,
          'infoData[3].name': re.data.peri_cn,
          'infoData[4].name': re.data.peri_notice,
          'infoData[5].name': re.data.check_timer,
          'infoData[6].name': re.data.new_period,
          'infoData[7].name': re.data.media_id,
          'infoData[8].name': re.data.peri_page_info,
          'infoData[9].name': re.data.peri_keys_info,
          'infoData[10].name': re.data.peri_demo_info,
          'infoData[11].name': re.data.peri_same_info,
          'infoData[12].name': re.data.peri_pcid,
          'infoData[13].name': re.data.peri_refer_info,
          'infoData[14].name': re.data.periis_cert,
          'infoData[15].name': re.data.peri_bill_info,
          'infoData[15].name': re.data.peri_other_info,
        })
      } else {
        wx.showToast({
          title: re.msg,
          icon: 'none',
          duration: 2000
        })
      }
    }, function (re) {
      wx.showToast({
        title: '数据走丢了。。。',
        icon: 'none',
        duration: 2000
      })
    });
  },
  onChange(e) {
    this.setData({
      active: e.detail.index
    })
    if (e.detail.index == 1) {
      this.getQCData()
    }
  },

  onContribution() {
    let that = this

    //判断用户是否已经登录
    let userInfo = commomUser.getUserInfo();
    if (!userInfo) {
      wx.showModal({
        title: '登录提示',
        content: '您还未登录，请先登录',
        success: function (res) {
          if (res.confirm) {
      
            let url = 'pages/peris/detail/index&peris_id='+that.data.periId;
            wx.navigateTo({
              url: '/pages/users/login/index?url='+url
            })
          }
        }
      });
      return;
    }
    wx.navigateTo({
      url: '/pages/contribute/contribute?id=' + that.data.periId
    })
  },
  showPopup() {
    this.setData({
      show: true
    });
  },

  onClose() {
    this.setData({
      show: false
    });
  },
  onChat() {
    let that = this;
    //判断用户是否已经登录
    let userInfo = commomUser.getUserInfo();
    if (!userInfo) {
      wx.showModal({
        title: '登录提示',
        content: '您还未登录，请先登录',
        success: function (res) {
          if (res.confirm) {
      
            let url = 'pages/peris/detail/index&peris_id='+that.data.periId;
            wx.navigateTo({
              url: '/pages/users/login/index?url='+url
            })
          }
        }
      })
    } else {
      wx.navigateTo({
        url: '/pages/chat/chat?peris_id='+that.data.periId,
      })
    }
  },
})